package com.boot.doc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.List;

/**
 * @author songyake
 * @Date: 2023/03/27
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Document(indexName = "users", shards = 2, replicas = 1 ,createIndex = true)
public class User {
    @Id
    private Long bid;
    @Field(type = FieldType.Text)
    private String userName;
    @Field(type = FieldType.Integer)
    private Integer age;
    @Field(type = FieldType.Text)
    private String phone;
    @Field(type = FieldType.Nested)
    private List<ChildUser> fans;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @ToString
    @Document(indexName = "users", shards = 2, replicas = 1 ,createIndex = true)
    public static class ChildUser {
        @Id
        private Long bid;
        @Field(type = FieldType.Text)
        private String userName;
        @Field(type = FieldType.Integer)
        private Integer age;
        @Field(type = FieldType.Text)
        private String phone;
    }
}



